package com.itlaobing.test;

import java.util.concurrent.locks.ReentrantLock;

public class ThreadTest4 {
    private  static class MyRun implements Runnable{//实现Runnable接口
        private volatile int count=1;
//        ReentrantLock reentrantLock =new ReentrantLock();
        @Override
        public  void run() {
//            reentrantLock.lock();
            if(count>0) {
//                try {
//                    Thread.sleep(10);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
                count--;
                System.out.println(Thread.currentThread().getName() + ":" + count);
            }
//            reentrantLock.unlock();
        }
    }

    public static void main(String[] args) {
        MyRun myRun=new MyRun();
        for (int i = 0; i <2 ; i++) {
            new Thread(myRun).start();
        }
    }
}
